#include <iostream>
#include <cstdio>
#include <string>

#define max 100000
#define maxk 30

using namespace std;

int f[max];
int a[max][maxk];
int n, k;

void inp()
{
  cin >> n >> k;
  for (int i = 1; i <= n; i++) cin >> f[i];
}
 
void init()
{
  for (int i = 1; i <= k; i++)
  {
    a[0][i] = 0;
    for (int j = 1; j <= n; j++) a[j][i] = a[j-1][i] + (f[j] >> i) && 1;
    for (int j = 1; j <= n; j++) a[j][i] = a[j][i] - a[j][1];
  }
}

void swap(int i, int j)
{ 
  for (int r = 1; r <= k; r++)
  {
    int temp = a[i][r];
    a[i][r] = a[j][r];
    a[j][r] = temp;
  }      
}
void sort(int h, int l, int r)
{
  if (l >= r) return;
  int i = l;
  int j = r;
  k = a[(l+r)/2][h];
  while (i <= j)
  {
    while (a[i][h] < k) i++;
    while (a[j][h] > k) j--;
    if (i <= j)
    {
      swap(i, j);
      i++; j--;
    }    
  }
  sort(h, i, r); sort(h, l, j);
}

void process()
{
  init();  
  for (int i = 1; i <= k; i++)
  {
    sort(i, 1, n);
  }
}
 
void out()
{
}
 
main()
{
  freopen("lineup.in", "r", stdin);
  freopen("lineup.out", "w", stdout); 
  
  inp();
  process();
  out();        
  return 0;
}
